route.js 960 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // app/api/branches/[branch]/[year]/months/route.js
  2. import { NextResponse } from "next/server";
  3. import { listMonths } from "@/lib/storage";
  4. /**
  5. * GET /api/branches/[branch]/[year]/months
  6. *
  7. * Returns the list of month folders for a given branch and year.
  8. * Example: /api/branches/NL01/2024/months → { months: ["01", "02", ...] }
  9. */
  10. export async function GET(request, ctx) {
  11. const { branch, year } = await ctx.params;
  12. console.log("[/api/branches/[branch]/[year]/months] params:", {
  13. branch,
  14. year,
  15. });
  16. if (!branch || !year) {
  17. return NextResponse.json(
  18. { error: "branch oder year fehlt" },
  19. { status: 400 }
  20. );
  21. }
  22. try {
  23. const months = await listMonths(branch, year);
  24. return NextResponse.json({ branch, year, months });
  25. } catch (error) {
  26. console.error("[/api/branches/[branch]/[year]/months] Error:", error);
  27. return NextResponse.json(
  28. { error: "Fehler beim Lesen der Monate: " + error.message },
  29. { status: 500 }
  30. );
  31. }
  32. }